/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package proms.net.conexao;

import java.sql.*;
import java.util.*;

public class Conexao {
	private static Properties param = new Properties();
	private static Connection conn=null;

	@SuppressWarnings("finally")
	public static Connection conecta() {
		try {
			param.load(Conexao.class.getResourceAsStream("bancodedados.propriedades"));
			String driver = param.getProperty("driver");
			String url = param.getProperty("url");
			String login = param.getProperty("usuario");
			String senha = param.getProperty("senha");
			Class.forName(driver);
			conn = DriverManager.getConnection(url, login, senha);
			//System.out.println("Conectou");
		} catch (SQLException ex) {
			//JFileChooser jf = new JFileChooser("C:\\");
			//jf.setVisible(true);
			System.out.println(ex.getMessage());
		} catch (ClassNotFoundException ex) {
			System.out.println(ex.getMessage());

		}finally{
			return conn;
		}
	}
	public static void desconecta() {
		try {
			if (conn!=null ){
				conn.close();
			}
			//System.out.println("Desconectou");
		} catch(SQLException ex) {
			System.err.println(ex);
		}

	}


}
